async function login() {
    let form = document.querySelector('.login-form')
    let data = serialize(form, { hash: true, empty: true })
    let { username, password } = data
    if (username.trim() === '' || password.trim() === '') {
        return toast('用户名或密码不能为空')
    }
    try {
        let res = await axios.post('/login', data)
        if (res.code == 10000) {
            toast(res.message)
            localStorage.setItem('token', res.data.token)
            localStorage.setItem('username', res.data.username)
            setTimeout(() => {
                location.href = './index.html'
            }, 666)
        } else {
            toast(res.message)
            form.reset()
        }
    } catch (err) {
        toast(err.response.data.message)
        form.reset()
    }
}
// login()
let btn = document.querySelector('#btn-login')
btn.addEventListener('click', login)
document.querySelector('.small ').addEventListener('click', function () {
    location.href = './register.html'
})